package com.example.deomspringbootspark01.controller;

import com.example.deomspringbootspark01.damain.BookBean;
import com.example.deomspringbootspark01.damain.BookRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.ws.RequestWrapper;
import java.awt.print.Book;
import java.util.Iterator;

@RestController
@RequestMapping("/books")
public class BookController {

    private BookRepository bookRepository;
    public BookController(@Autowired BookRepository bookRepository) {
        this.bookRepository = bookRepository;
    }
    @RequestMapping(value = "", method = RequestMethod.GET)
    public Iterable<BookBean> getAllBooks(){
        return bookRepository.findAll();
    }
    @RequestMapping(value = "/{bookName}", method = RequestMethod.GET)
    public BookBean getBook(String name){
        return bookRepository.findBookByName(name);
    }
}
